package com.lb.jwitter.action;


import java.text.DateFormat; 
import java.text.SimpleDateFormat; 
import java.util.ArrayList; 
import java.util.Map; 
 import com.opensymphony.xwork2.ActionContext; 
import java.util.Collection; 
import com.lb.jwitter.util.ApplicationContextProvider; 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; 
import org.springframework.test.context.ContextConfiguration;
import java.util.Date; 
import java.util.GregorianCalendar; 
import javax.xml.datatype.DatatypeFactory; 
import javax.xml.datatype.XMLGregorianCalendar; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 
import com.lb.jwitter.service.ConditionReport; 
import com.lb.jwitter.util.Message; 
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.TblQuyenChiTietService;import com.lb.jwitter.service.TblTaiKhoan;import com.lb.jwitter.service.TblRangBuocDangKyMonHoc;
import com.lb.jwitter.service.TblRangBuocDangKyMonHocService;
import com.lb.jwitter.service.TblCTDTChuyenNganh;
import com.lb.jwitter.service.TblCTDTChuyenNganhService;

import com.lb.jwitter.service.TblCTDTMonHoc;
import com.lb.jwitter.service.TblCTDTMonHocService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblRangBuocDangKyMonHocUpdateAction{
    private int pageSize; 
    public int getPageSize() {
       return pageSize;
 }

    public void setPageSize(int pageSize) { this.pageSize = pageSize; }

    private int page; 
    public int getPage() { return page; }

    public void setPage(int page) { this.page = page; }

    private int pages; 
    public int getPages() { return pages; }

    public void setPages(int pages) { this.pages = pages; }

    private String dataString; 
    public String getDataString() { return dataString; }

    private Message msg; 
    public Message getMsg() { return msg; }

    private int id; 
    public int getId() {
       return id;
 }

    public void setId(int id) {
       this.id = id;
 }

    private int chuyenNganhId; 
    public void setChuyenNganhId(int chuyenNganhId) {
       this.chuyenNganhId = chuyenNganhId;
 }

    public int getChuyenNganhId() {
       return chuyenNganhId;
 }

    private TblCTDTChuyenNganhService tblCTDTChuyenNganhService; 

    private int monHocId; 
    public void setMonHocId(int monHocId) {
       this.monHocId = monHocId;
 }

    public int getMonHocId() {
       return monHocId;
 }

    private TblCTDTMonHocService tblCTDTMonHocService; 

    private String khoaHoc; 
    public void setKhoaHoc(String khoaHoc) {
       this.khoaHoc = khoaHoc;
 }

    public String getKhoaHoc() {
       return khoaHoc;
 }

    private int soTinChiTichLuy; 
    public void setSoTinChiTichLuy(int soTinChiTichLuy) {
       this.soTinChiTichLuy = soTinChiTichLuy;
 }

    public int getSoTinChiTichLuy() {
       return soTinChiTichLuy;
 }

    private int soTinChiConLai; 
    public void setSoTinChiConLai(int soTinChiConLai) {
       this.soTinChiConLai = soTinChiConLai;
 }

    public int getSoTinChiConLai() {
       return soTinChiConLai;
 }

    private String anhVan; 
    public void setAnhVan(String anhVan) {
       this.anhVan = anhVan;
 }

    public String getAnhVan() {
       return anhVan;
 }

    private String ghiChu; 
    public void setGhiChu(String ghiChu) {
       this.ghiChu = ghiChu;
 }

    public String getGhiChu() {
       return ghiChu;
 }

    private TblRangBuocDangKyMonHoc tblRangBuocDangKyMonHoc; 
    public void setTblRangBuocDangKyMonHoc (TblRangBuocDangKyMonHoc tblRangBuocDangKyMonHoc) {
        this.tblRangBuocDangKyMonHoc = tblRangBuocDangKyMonHoc;
 }

    private TblRangBuocDangKyMonHocService tblRangBuocDangKyMonHocService; 

	private int preUpdate(Message msg, TblRangBuocDangKyMonHoc obj ){ 
        msg.setPreMessage_b(true); 
        msg.setPreMessage_s("success"); 
        return 1; 
    } 
	private int postUpdate(Message msg, TblRangBuocDangKyMonHoc obj ){ 
        msg.setPostMessage_b(true); 
        msg.setPostMessage_s("success"); 
        return 1; 
    } 
  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
 public String execute() throws Exception 
{ 
 try{ 	
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_RangBuoc_DangKyMonHoc", "sua")){ 
        return "noprivilege"; 
    } 
        tblRangBuocDangKyMonHocService = (TblRangBuocDangKyMonHocService) context.getBean("tbl_RangBuoc_DangKyMonHocClient"); 
        tblCTDTChuyenNganhService = (TblCTDTChuyenNganhService) context.getBean("tbl_CTDT_ChuyenNganhClient"); 

        tblCTDTMonHocService = (TblCTDTMonHocService) context.getBean("tbl_CTDT_MonHocClient"); 

        msg = new Message(); 
        tblRangBuocDangKyMonHoc = tblRangBuocDangKyMonHocService.gettblRangBuocDangKyMonHoc(new Long(id)); 
//        tblRangBuocDangKyMonHoc.setChuyenNganhId(tblCTDTChuyenNganhService.gettblCTDTChuyenNganh(new Long(chuyenNganhId))); 
//        tblRangBuocDangKyMonHoc.setMonHocId(tblCTDTMonHocService.gettblCTDTMonHoc(new Long(monHocId))); 
        tblRangBuocDangKyMonHoc.setKhoaHoc(khoaHoc); 
        tblRangBuocDangKyMonHoc.setSoTinChiTichLuy(soTinChiTichLuy); 
        tblRangBuocDangKyMonHoc.setSoTinChiConLai(soTinChiConLai); 
        tblRangBuocDangKyMonHoc.setAnhVan(anhVan); 
        tblRangBuocDangKyMonHoc.setGhiChu(ghiChu); 
        
        preUpdate(msg,tblRangBuocDangKyMonHoc); 
        
       if (msg.isPreMessage_b()) 
       { 
           tblRangBuocDangKyMonHocService.updatetblRangBuocDangKyMonHoc(tblRangBuocDangKyMonHoc); 
           postUpdate(msg, tblRangBuocDangKyMonHoc); 
           if (msg.isPostMessage_b() == false) 
           { 
               return Action.ERROR; 
           } 
       }else{ 
           return Action.ERROR; 
       } 

        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
         System.out.println("Loi Update tbl_RangBuoc_DangKyMonHoc Action"); 
         e.printStackTrace(); 
         return Action.ERROR; 
 } 
 } 
 } 
 
